# -*- coding:utf-8 -*-
from com import TimeUtils
from parse_trace import ExcelTools, ProcessInfo, OriginTrace


def main(report_dir, proc_list):
    assert isinstance(proc_list, list), '目标进程列表参数类型出错'
    excel_tools = ExcelTools(report_dir + 'reports.xlsx')
    launch_time_list = []
    for proc in proc_list:
        assert isinstance(proc, ProcessInfo)
        origin_t = OriginTrace(proc.file_dir, proc.file_name)
        proc.init_data(origin_t)
        time = proc.get_launch_time()
        data = {
            'proc_name': proc.name,
            'time_ms': time
        }
        launch_time_list.append(data)
        print data
    excel_tools.add_sheet('launch_time', launch_time_list)


def parse_all_func_time(proc):
    assert isinstance(proc, ProcessInfo)
    origin_t = OriginTrace(proc.file_dir, proc.file_name)
    proc.init_data(origin_t)
    path=proc.file_dir+proc.name+'_'+TimeUtils.format_current_to_file_name()+'.xls'
    excl=ExcelTools(path)
    excl.add_sheet(proc.name + "_func", proc.func_list)



if __name__ == '__main__':
    # c=ProcessInfo('./data/', '16851.html', 'camera', '16851')
    c=ProcessInfo('./data/mydemo/', 'bitmap.html', 'bitmap', '9191')
    parse_all_func_time(c)


    # src_dir = './data/mydemo/'
    # appList = [
    #     ProcessInfo(src_dir, 'bitmap.html', 'bitmap', '9191'),
    #     ProcessInfo(src_dir, 'database.html', 'database', '9305'),
    #     ProcessInfo(src_dir, 'gallery.html', 'gallery', '9407'),
    #     ProcessInfo(src_dir, 'helloworld.html', 'helloworld', '9505'),
    #     ProcessInfo(src_dir, 'views.html', 'views', '9584'),
    # ]
    # # main('./report/', appList)
    #
    # src_dir = './data/'
    # appList = [
    #     ProcessInfo(src_dir, 'all.html', 'bitmap', '25417'),
    #     ProcessInfo(src_dir, 'all.html', 'database', '25464'),
    #     ProcessInfo(src_dir, 'all.html', 'gallery', '25515'),
    #     ProcessInfo(src_dir, 'all.html', 'helloworld', '9505'),
    #     ProcessInfo(src_dir, 'all.html', 'views', '9584'),
    # ]
    # main('./report/', appList)
